﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ClientModel;
using LocalServerApp;

namespace Client
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, IMainWindowObserver
    {
        private static Frame frmMainContent;
        KortService kortService = new KortService();
        

        public MainWindow()
        {
            InitializeComponent();
            frmMainContent = new Frame();
            frmMainContent.NavigationUIVisibility = NavigationUIVisibility.Hidden;
            cntpre.Content = frmMainContent;
            pagSession session = pagSession.getInstance();
            kortService.RegObserver(session);
            pagStartUp pagStart = new pagStartUp();
            SetPage(pagStart);
            this.Show();
            this.WindowStyle = System.Windows.WindowStyle.None;
            this.WindowState = System.Windows.WindowState.Maximized;
            Service.getInstance().setWindow(this);
        }

        public static void SetPage(Page page)
        {
            frmMainContent.Content = page;
        }

        private void Window_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            kortService.cardReaderInput(e.Text);
        }

        #region IMainWindowObserver Members

        public void notify()
        {
            if (frmMainContent.Content.GetType().Equals(pagSession.getInstance().GetType()))
            {
                pagSession actualPage = (pagSession)frmMainContent.Content;
                actualPage.dimMe();
            }
            winForgottenClothes winFC = new winForgottenClothes();
            winFC.ShowDialog();
            if(winFC.DialogResult == true)
            {

                if (frmMainContent.Content.GetType().Equals(pagSession.getInstance().GetType()))
                {
                    pagSession actualPage = (pagSession)frmMainContent.Content;
                    actualPage.unDimMe();
                }

                SetPage(new pagStartUp());
            }
            
        }

        #endregion
    }
}